package com.yly.order.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.yly.order.entity.Product;
import com.yly.order.feign.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

	@Autowired
	private ProductFeignClient productFeignClient;

	/**
	 */
	@RequestMapping(value = "/buy/feign/{id}",method = RequestMethod.GET)
	public Product findFeignById(@PathVariable Long id) throws Exception {

		if(id != 1) {
			int i = 1/0;
			throw  new Exception("太忙了");
		}

		return  productFeignClient.findById(id);
	}

	/**
	 * 指定统一的降级方法
	 *  * 参数 : 没有参数
	 */
	public Product defaultFallBack() {
		Product product = new Product();
		product.setProductName("触发统一的降级方法");
		return product;
	}
}
